package com.example.demo.leetcode.top100;

import java.util.HashMap;
import java.util.Map;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _1两数之和
 * @description
 * @date 2023/06/02 21:27
 * <p>
 * ******************************************************
 */
public class _1两数之和 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> record = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            if (record.containsKey(target - nums[i])) {
                return new int[]{i, record.get(target - nums[i])};
            }
            record.put(nums[i], i);
        }
        return null;
    }
}
